<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>用户导出记录</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/plugin/zTree_v3/css/zTreeStyle/zTreeStyle.css">
    <link rel="stylesheet" href="/static/plugin/zTree_v3/css/demo.css">
    <script src="/static/plugin/zTree_v3/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="/static/layui/layui.js"></script>
    <script src="/static/plugin/ztree/js/jquery.ztree.core.js"></script>
    <script src="/static/plugin/ztree/js/jquery.ztree.excheck.js"></script>
    <script src="/static/plugin/ztree/js/jquery.ztree.exedit.js"></script>
    <script type="text/javascript" src="/static/js/base.js"></script>
<body class="layui-anim">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>用户导出记录</cite>
        </a>
      </span>
</div>
<div class="x-body">

    <div class="layui-row" style="margin-bottom: 18px">
        <div class="layui-form">
            <div class="layui-input-inline">

                <div class="layui-input-inline" style="width: 400px">
                    <input class="layui-input" id="keyword01" placeholder="请输入支持搜索关键词、公司名、人名、专利号等">
                </div>
                <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
            </div>
        </div>
    </div>

    <xblock>
        <!--<button class="layui-btn" ><i class="layui-icon"></i>导入</button>-->
        <button type="button" class="layui-btn" onclick="upload()">导入</button>
    </xblock>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
</div>

<script>

    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var M = date.getMinutes();
        M = M<10?("0"+M):M;
        var str = y+"-"+m+"-"+d+" "+h+":"+M;
        return str;
    }

    $(document).ready(function () {
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month);
        $('#dateTime').val(today);
    })

    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var form=layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date1',
            value:new Date()
        });
        laydate.render({
            elem: '#date2'
        });

        laydate.render({
            elem: '#date3',
            type: 'month',
            value: new Date(),
            done:function(value, date, endDate) {
                $('#dateTime').val(value);
            }
        });

        var $ = layui.jquery, active = {
            reload:function () {
                var whereStr = ""
                var keyword01 = $("#keyword01").val();
                if(keyword01 != ""){
                    whereStr += " and ("
//                    whereStr += " open_number like '%" + keyword01+"%'"
//                    whereStr += " or apply_by like '%" + keyword01+"%'"
//                    whereStr += " or inventor like '%" + keyword01+"%'"
//                    whereStr += " or name like '%" + keyword01+"%'"
//                    whereStr += " or summary like '%" + keyword01+"%'"
                    whereStr += " CONTAINS(open_number, '%" + keyword01+"%')"
                    whereStr += " or CONTAINS(apply_by, '%" + keyword01+"%')"
                    whereStr += " or CONTAINS(inventor, '%" + keyword01+"%')"
                    whereStr += " or CONTAINS(name, '%" + keyword01+"%')"
                    whereStr += " or CONTAINS(summary, '%" + keyword01+"%')"
                    whereStr += " )"
                }
                table.reload('contentTable',{
                    method:'get'
                    ,where:{
                        'whereStr':whereStr
                    }
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        }

        table.render({
            elem: '#tableList'
            ,id:'contentTable'
            ,url: '/patent/web/queryPage'
            ,toolbar: '#toolbar'
            ,request: {   //如果无需自定义请求参数，可不加该参数
                pageName: 'page' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,response: {   //如果无需自定义数据响应名称，可不加该参数
                countName: 'count' //规定数据总数的字段名称，默认：count
                ,dataName: 'data' //规定数据列表的字段名称，默认：data
            }
            ,where:{

            }
            , cols: [
                [ {field:'uid', title:'序号', width: '5%', type:'numbers',align:'center'}
                    ,{
                    field: 'openNumber',
                    title: '公开（公告）号'
                }, {
                    field: 'name',
                    title: '标题',
                    templet: function(d){
                        var value = "<span title='"+d.summary+"'>"+d.name+"</span>";
                        return value;
                    },
                }, {
                    field: 'legalStatus',
                    title: '法律状态/事件'
                }, {
                    field: 'applyBy',
                    title: '当前申请（专利权）人'
                }, {
                    field: 'inventor',
                    title: '发明人'
                }, {
                    field: 'applyDate',
                    title: '申请日'
                }, {
                    field: 'openDate',
                    title: '公开（公告）日'
                }
                ]
            ]
            , page: true
            ,totalRow: true
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#3388CB', 'color': '#fff','font-weight':'bold',
                })
            }
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //监听工具条
        table.on('tool(tableList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                detail('编辑角色', 'updateDept?id=' + data.deptId, 600, 350);
            } else if (obj.event === 'del') {
                layer.confirm('确定删除部门？[<label style="color: #00AA91;">' + data.deptName + '</label>]?', {
                    btn: ['确定','取消'] //按钮
                }, function(index){
                    del(data.deptId)
                })

            } else if (obj.event === 'edit') {
                update('编辑部门', 'updateDept?id=' + data.deptId, 700, 450);
            }
        });


        form.verify({
            deptName:function (value, item) {
                if(value.trim() == ''){
                    return '部门名称不能为空';
                }
            },
            remark:function (value, item) {
                if(value.trim() == ''){
                    return '备注不能为空';
                }
            },
        })

        window.upload = function (){
            layer.open({
                type: 1 					//Page层类型
                ,area: ['380px', '200px'] 	//宽  高
                ,title: '上传文件'
                ,shade: 0.6 				//遮罩透明度
                ,maxmin: true 				//允许全屏最小化
                ,anim: 1 					//0-6的动画形式，-1不开启
                ,content:'<!-- 导入模板 -->'
                +'<div class="modal fade" id="importDiv1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">'
                +'<div class="modal-dialog" role="document">'
                +'<div class="modal-content">'
                +'<div class="modal-body">'
                +'<form id="importForm" class="layui-form" enctype="multipart/form-data">'
                +'<div title="Excel导入操作" style="margin-left: 105px; padding: 5px">'
                +'<input id="file" name="file" type="file" style="margin-bottom: 20px" accept=".TXT"/>'
                +'</div>'
                +'</form>'
                +'<div align="center">'
                +'<button class="layui-btn layui-btn-blue" onclick="uploadBtn1()">导入</button>'
                +'&emsp;&emsp;'
                +'<button class="layui-btn layui-btn-primary" onclick="close_selection_box()">取消</button>'
                +'</div>'
                +'</div>'
                +'</div>'
                +'</div>'
                +'</div>'
                ,success: function(){
                    $("#file").val(null)
                    form.render();
                }
            });
        }
        /**
         * 公用关闭弹框(AJAX方式)
         */
        window.close_selection_box = function () {
            layer.closeAll();
            return false;
        };
        /**
         * 把数据传到后台
         */
        window.uploadBtn1 = function(){
            let file=$("#file").val();
            if(file == null || file == "") {
                layer.alert("请选择上传文件",{icon :5});
                return;
            }else{
                let filename=file.substr(file.lastIndexOf("."));
                filename = filename.toLowerCase()
                var type = ".TXT"
                type = type.toLowerCase()
                if(type.indexOf(filename) == -1){
                    layer.alert("请上传限定格式的文件",{icon :5});
                    return;
                }
            }
            var formData = new FormData($("#importForm")[0]);
            $.ajax({
                url: '/patent/upload' ,
                type: 'post',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (res) {
                    if (res.code == 1) {
                        layer.closeAll();
                        table.reload('contentTable',{
                            method:'get'
                            ,page: {
                                curr: 1//重新从第 1 页开始
                            }
                        });
                        layer.msg("导入成功！",{icon :6});
                    }else{
                        layer.msg("导入失败！",{icon :6});
                    }
                },
                error: function (res) {
                    layer.msg("导入失败！",{icon :5});
                }
            });
        };
    });
</script>
</body>

</html>
